import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

/* Layout */
import Layout from '@/layout';

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
    // 登录
    {
        path: '/login',
        component: () =>
            import('@/views/login2/index'),
        hidden: true
    },
    // 404
    {
        path: '/404',
        component: () =>
            import('@/views/404'),
        hidden: true
    },
    // 认证
    {
        path: '/certification',
        component: () =>
            import('@/views/certification'),
        hidden: true
    },
    // 注册
    {
        path: '/signUp',
        component: () =>
            import('@/views/signUp'),
        hidden: true
    },
    // 已注册
    {
        path: '/registered',
        component: () =>
            import('@/views/registered'),
        hidden: true,
        children: [{
                path: '/',
                name: 'qiye',
                component: () =>
                    import('@/views/registered/qiye')
            },
            {
                path: '/geren',
                component: () =>
                    import('@/views/registered/geren')
            },
            {
                path: '/moneyInfo',
                component: () =>
                    import('@/views/registered/moneyInfo')
            },
            {
                path: '/money',
                component: () =>
                    import('@/views/registered/money')
            },
            {
                path: '/success',
                component: () =>
                    import('@/views/registered/success')
            }
        ]
    },
    // 后台首页
    {
        path: '/',
        component: Layout,
        redirect: '/dashboard',
        children: [{
            path: 'dashboard',
            name: 'Dashboard',
            component: () =>
                import('@/views/dashboard/index'),
            meta: {
                title: '首页',
                icon: 'dashboard',
            }
        }]
    },
    // 合同管理
    {
        path: '/contract',
        component: Layout,
        redirect: 'noRedirect',
        name: 'Contract',
        meta: {
            title: '合同管理',
            icon: 'excel'
        },
        children: [{
            path: '/workers',
            name: 'Workers',
            component: () =>
                import('@/views/contract/workers/index'),
            meta: {
                title: '工人合同管理',
                keepAlive: true,
            },
            children: [{
                    path: 'signedContract',
                    name: 'workersSignedContract',
                    component: () =>
                        import('@/views/contract/workers/components/page/signedContract'),
                    meta: {
                        title: '查看待签订合同',
                        keepAlive: true
                    },
                    hidden: true,
                    children: [{
                        path: '/workersCancelList',
                        name: 'workersCancelList',
                        component: () =>
                            import('@/views/contract/workers/components/page/cancelList'),
                        meta: {
                            title: '查看已驳回合同',
                            keepAlive: true
                        },
                        hidden: true
                    }]
                },
                {
                    path: 'workersSubcontractList',
                    name: 'workersSubcontractList',
                    component: () =>
                        import('@/views/contract/workers/components/page/subcontractList'),
                    meta: {
                        title: '查看已签订合同',
                        keepAlive: true,
                        breadcrumb: false
                    },
                    hidden: true,
                    children: [{
                        path: 'workersContractList',
                        name: 'workersContractList',
                        component: () =>
                            import('@/views/contract/workers/components/page/contractList'),
                        meta: {
                            title: '合同列表',
                            keepAlive: true
                        },
                        hidden: true
                    }]
                }
            ]
        }, {
            path: '/team',
            name: 'Team',
            component: () => import('@/views/contract/team'),
            meta: {
                title: '班组合同管理'
            }
            ,children:[{
                path: '/',
                name: 'ContractAdmin',
                component: () => import('@/views/contract/team/contractAdmin'),
                hidden:true,
                meta:{
                    title: '班组合同',
                    activeMenu: '/team',
                    breadcrumb: false
                },
                children:[{
                    path: 'signedTeam',
                    name: 'SignedTeam',
                    component: () => import('@/views/contract/team/contractAdmin/signedTeam'),
                    hidden:true,
                    meta:{
                        title: '已签订班组合同',
                        activeMenu: '/team'
                    },
                    children:[{
                        path: 'signedTeamList',
                        name: 'SignedTeamList',
                        component: () => import('@/views/contract/team/contractAdmin/signedTeamList'),
                        hidden:true,
                        meta:{
                            title: '合同列表',
                            activeMenu: '/team'
                        }
                    }]
                },{
                    path: 'unsignedTeam',
                    name: 'UnsignedTeam',
                    component: () => import('@/views/contract/team/contractAdmin/unsignedTeam'),
                    hidden:true,
                    meta:{
                        title: '待签订班组合同',
                        activeMenu: '/team'
                    }
                }]
            },{
                path: 'canceled',
                name: 'Canceled',
                component: () => import('@/views/contract/team/canceled'),
                hidden:true,
                meta:{
                    title: '已取消合同',
                    activeMenu: '/team'
                }
            },{
                path: 'startContruct',
                name: 'StartContruct',
                component: () => import('@/views/contract/team/startContract'),
                hidden:true,
                meta:{
                    title: '发起班组内包合同',
                    activeMenu: '/team'
                },
                children:[{
                    path: 'setSignedArea',
                    name: 'SetSignedArea',
                    component: () => import('@/views/contract/team/startContract/setSignedArea'),
                    hidden:true,
                    meta:{
                        title: '设定签署区',
                        activeMenu: '/team'
                    }
                }]
            }]
        },{
            path: '/subcontract',
            name: 'Subcontract',
            component: () => import('@/views/contract/subcontract'),
            meta: {
                title: '分包合同管理'
            }
            ,children:[{
                path: '/',
                name: 'SubcontractDefault',
                component: () => import('@/views/contract/subcontract/subcontract'),
                hidden:true,
                meta:{
                    title: '分包合同',
                    activeMenu: '/subcontract',
                    breadcrumb: false
                },
                children:[{
                    path: 'signedContract',
                    name: 'SignedSubcontract',
                    component: () => import('@/views/contract/subcontract/subcontractViews/signedContract'),
                    hidden:true,
                    meta:{
                        title: '已签订分包合同',
                        activeMenu: '/subcontract'
                    }
                },{
                    path: 'unsignedContract',
                    name: 'UnsignedSubcontract',
                    component: () => import('@/views/contract/subcontract/subcontractViews/unsignedContract'),
                    hidden:true,
                    meta:{
                        title: '待签订分包合同',
                        activeMenu: '/subcontract'
                    }
                }]
            },{
                path: 'refused',
                name: 'RefusedSubcontract',
                component: () => import('@/views/contract/subcontract/refused'),
                hidden:true,
                meta:{
                    title: '已拒绝合同',
                    activeMenu: '/subcontract'
                }
            }]
        }]
    },
    {
        //班组管理
        path: '/teamAdmin',
        name: 'TeamAdmin',
        component: Layout,
        meta:{
            title: '班组管理',
            icon:'tree'
        },
        children:[{
            path:'/',
            component: () => import('@/views/contract/team/teamAdmin'),
            meta:{
                title:'班组管理',
                breadcrumb:false
            },
            hidden:true
        }]
    },
    // 测试
    {
        path: '/example',
        component: Layout,
        redirect: '/example/table',
        name: 'Example',
        meta: {
            title: 'Example',
            icon: 'example',
            roles: ['admin']
        },
        hidden: true,
        children: [{
                path: 'table',
                name: 'Table',
                component: () =>
                    import('@/views/table/index'),
                meta: {
                    title: 'Table',
                    icon: 'table'
                }
            },
            {
                path: 'tree',
                name: 'Tree',
                component: () =>
                    import('@/views/tree/index'),
                meta: {
                    title: 'Tree',
                    icon: 'tree'
                }
            }
        ]
    },
    // elementUI 表单完整示例
    {
        path: '/form',
        component: Layout,
        hidden: true,
        children: [{
            path: 'index',
            name: 'Form',
            component: () =>
                import('@/views/form/index'),
            meta: {
                title: 'Form',
                icon: 'form'
            }
        }]
    },
    // 导航示例
    {
        path: '/nested',
        component: Layout,
        redirect: '/nested/menu1',
        name: 'Nested',
        hidden: true,
        meta: {
            title: 'Nested',
            icon: 'nested'
        },
        children: [{
                path: 'menu1',
                component: () =>
                    import('@/views/nested/menu1/index'), // Parent router-view
                name: 'Menu1',
                meta: {
                    title: 'Menu1'
                },
                children: [{
                        path: 'menu1-1',
                        component: () =>
                            import('@/views/nested/menu1/menu1-1'),
                        name: 'Menu1-1',
                        meta: {
                            title: 'Menu1-1'
                        }
                    },
                    {
                        path: 'menu1-2',
                        component: () =>
                            import('@/views/nested/menu1/menu1-2'),
                        name: 'Menu1-2',
                        meta: {
                            title: 'Menu1-2'
                        },
                        children: [{
                                path: 'menu1-2-1',
                                component: () =>
                                    import('@/views/nested/menu1/menu1-2/menu1-2-1'),
                                name: 'Menu1-2-1',
                                meta: {
                                    title: 'Menu1-2-1'
                                }
                            },
                            {
                                path: 'menu1-2-2',
                                component: () =>
                                    import('@/views/nested/menu1/menu1-2/menu1-2-2'),
                                name: 'Menu1-2-2',
                                meta: {
                                    title: 'Menu1-2-2'
                                }
                            }
                        ]
                    },
                    {
                        path: 'menu1-3',
                        component: () =>
                            import('@/views/nested/menu1/menu1-3'),
                        name: 'Menu1-3',
                        meta: {
                            title: 'Menu1-3'
                        }
                    }
                ]
            },
            {
                path: 'menu2',
                component: () =>
                    import('@/views/nested/menu2/index'),
                meta: {
                    title: 'menu2'
                }
            }
        ]
    },
    // 404 配置
    {
        path: '*',
        redirect: '/404',
        hidden: true
    }
]

// 创建路由对象
const createRouter = () => new Router({
    // 路由模式 hash
    scrollBehavior: () => ({
        y: 0
    }),
    routes: constantRoutes
});

// 路由对象实例化
const router = createRouter();

// 路由对象重定向
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}




export default router;